package com.wechat.order.service.UserService.Impl;

import com.wechat.order.dataobject.userInfo;
import com.wechat.order.form.UserForm;
import com.wechat.order.repository.UserRepository;
import com.wechat.order.service.UserService.UserService;
import com.wechat.order.util.KeyUtils;
import com.wechat.order.util.mail.EmailUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import java.util.UUID;

/**
 * Created by zzy on 2017/12/27.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public void register(UserForm userForm) throws Exception {
        userInfo user=new userInfo();
        BeanUtils.copyProperties(userForm,user);
        user.setState(0);
        user.setCode(UUID.randomUUID().toString());
        user.setUid(KeyUtils.getUniqueKey());
        userRepository.save(user);
        //发送激活邮件
        EmailUtil.sendMail(user.getEmail(),user.getCode());
    }
}
